package com.hp.attendance.service;
import com.hp.attendance.dao.DepartmentDao;
import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.PageInfo;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;



public class DepartmentService {
    private DepartmentDao departmentDao = new DepartmentDao();

    //查询
    public List<Department> getList() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {

        return departmentDao.getList();
    }

    //分页查询
    public PageInfo<Department> getPage(int pageNo, int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<Department> page = new PageInfo<Department>();

        //查询分页的数据
        List<Department> list = departmentDao.getLimitList(pageNo, pageSize);
        page.setRecords(list);
        //查询总记录条数
        long total = departmentDao.getTotal();
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int) Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;
    }

    //添加
    public void addDepartment(Department department) throws SQLException, IOException, ClassNotFoundException {
        departmentDao.addDepartment(department);
    }

    /**
     * 修改菜单
     *
     * @param department
     */
    public void updateDepartment(Department department) throws SQLException, IOException, ClassNotFoundException {
        departmentDao.updateDepartment(department);
    }

    /**
     * 删除菜单
     *
     * @param id
     */
    public void delDepartment(int id) throws SQLException, IOException, ClassNotFoundException {
        departmentDao.delDepartment(id);
    }


    //根据id查询对象
    public Department getDepartment(int id) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {

        return departmentDao.getDepartment(id);
    }

    //部门编号的最大值的查询
    public Integer getMaxDepartmentnumber() throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {

        return departmentDao.getMaxDepartmentnumber();
    }
}
